package io.yizoo.business.controller;

import io.elm.core.CoreController;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.UUID;

@RestController
@RequestMapping("/business/cms/news/io")
public class cms_news_ioController extends CoreController {

    @PostMapping("/Upload")
    public Object upload(@RequestParam("upload") MultipartFile file) {
        String uuid = UUID.randomUUID().toString();
        String module_name = "business_cms_news_io";
        String rel_id = uuid;
        String miniio_name = module_name + "/" + rel_id + "/" + file.getOriginalFilename();
        Object ret = Ctor.Minior.upload(file, miniio_name);
        return JsonResult(
                new KV("uploaded",true),
                new KV("url", "/api/business/cms/news/io/Viewer/" + uuid + "/" + file.getOriginalFilename())
        );
    }
    @GetMapping("/Viewer/{value1}/{value2}")
    public Object Viewer(@PathVariable("value1") String v1 ,@PathVariable("value2") String v2)
    {
        String module_name="business_cms_news_io";
        String miniio_name=module_name+"/"+v1+"/"+v2;
        return Ctor.Minior.read(miniio_name,v2);
    }
}